import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const TokenKey2 = 'Admin-Token2'
const ModulesKey = 'ModuleStr'
const UserKey = 'UserStr'
const DimesionKey = 'Dimesion-Flag'

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  return sessionStorage.removeItem(TokenKey)
}

export function getToken2() {
  return sessionStorage.getItem(TokenKey2)
}

export function setToken2(token) {
  return sessionStorage.setItem(TokenKey2, token)
}

export function removeToken2() {
  return sessionStorage.removeItem(TokenKey2)
}

export function getUserBaseId() {
  const json = sessionStorage.getItem(UserKey)
  if (!json) {
    return ''
  }
  const obj = JSON.parse(json)
  if (obj) {
    return obj.UserId
  }
  return ''
}
export function getUserBaseRetail() {
  const json = sessionStorage.getItem(UserKey)
  if (!json) {
    return ''
  }
  const obj = JSON.parse(json)
  if (obj) {
    return obj.RetailId
  }
  return ''
}
export function getUserBaseSupplier() {
  const json = sessionStorage.getItem(UserKey)
  if (!json) {
    return ''
  }
  const obj = JSON.parse(json)
  if (obj) {
    return obj.SupplierId
  }
  return ''
}
export function getUserBaseDomain() {
  const json = sessionStorage.getItem(UserKey)
  if (!json) {
    return ''
  }
  const obj = JSON.parse(json)
  if (obj) {
    return obj.Domain
  }
  return ''
}
export function setUserBase(userBase) {
  return sessionStorage.setItem(UserKey, userBase)
}
export function removeUserBase() {
  return sessionStorage.removeItem(UserKey)
}
export function getModules() {
  const result = sessionStorage.getItem(ModulesKey)
  if (!result) {
    return []
  } else {
    return JSON.parse(result)
  }
}

export function setModules(data) {
  const s = JSON.stringify(data)
  return sessionStorage.setItem(ModulesKey, s)
}

export function setDimension(data) {
  const s = JSON.stringify(data)
  return sessionStorage.setItem(DimesionKey, s)
}

export function getDimension() {
  const result = sessionStorage.getItem(DimesionKey)
  if (!result) {
    return []
  } else {
    return JSON.parse(result)
  }
}
